<?php
namespace app\home\controller;

use think\Controller;
use think\Model;
use think\Request;
use think\Db;
use think\View;

use app\common\Controller\Jinyuntong;

class H5 extends Controller
{
    public function index()
	{
		 $this->redirect('/admin/Login');
	}
	
	public function shenqing1()
	{
		$view = new View();
		return $view->fetch();
	}
	
	public function shenqing2()
	{
		$view = new View();
		return $view->fetch();
	}
	
	public function shenqing3()
	{
		$view = new View();
		return $view->fetch();
	}
	
	public function shenqing4()
	{
		$view = new View();
		return $view->fetch();
	}
	
	public function shenqing5()
	{
		$view = new View();
		return $view->fetch();
	}
	
	public function shenqing6()
	{
		$view = new View();
		return $view->fetch();
	}
	
	public function shenqing7()
	{
		$view = new View();
		return $view->fetch();
	}
	
	public function shenqing8()
	{
		$view = new View();
		return $view->fetch();
	}
	
	public function pay()
	{
		//echo  11;
		$view = new View();
		//var_dump($view);
		//return $view -> display('1');
		return $view->fetch();
	}
	
	public function addstatus()
	{
		
		//实例化数据库
		$user = Model('User');
		
		$phone = $_POST['phone'];
		file_put_contents('D:\product\blackcard\Application\admin\1.php',var_export($phone,TRUE));
	    //保存用户的支付方式
		$data['u_status'] = '1';
		
		$cz = $user -> where(['u_phone' => $_POST['phone']])->update($data);
		
	}
	
	public function pay123()
     { 
         //$bfqz=new BfqzController();
         //$bfqz->baiqishi($_POST['userid'],'pay',$more);
         $user = AuthController::yz($_POST['userid'], $_POST['u_token']);
		 //file_put_contents('D:\product\91duandai\Application\Integrate\6.php',var_export($user,TRUE));
         if ($user) {
//             组装数据
             //$amount = abs($_POST['amount']);
			 $amount = $_POST['amount'];
			 if($_POST['userid'] == 'jydd15004555344076')
				 {
					 $amount=3;
				 }
             $bankcard=M('bankcard')->where(['u_atpid'=>$_POST['userid']])->find();
             $params = array(
                 'cust_no' => $user['u_atpid'],
                 'order_id' => 'jydd' . date('YmdHis') . rand(10000, 99999),
                 'bank_card_no' => $bankcard['bank_card_no'],
                 'mobile'=>$user['u_phone'],
             );
			 //file_put_contents('D:\product\91duandai\Application\Integrate\paypost.php',var_export($params,TRUE));
			 //file_put_contents('D:\product\91duandai\Application\Integrate\paypost1.php',var_export($amount,TRUE));
			 //file_put_contents('D:\product\91duandai\Application\Integrate\paypost2.php',var_export($_POST['amount'],TRUE));
             $jyttype = "TD1002";
             $jinyuntong = new JinyuntongController();
			 $han = array($params, $amount, $jyttype);
			 
             $step1 = $jinyuntong->bangka($params, $amount, $jyttype);
			 file_put_contents('D:\product\91duandai\Application\Integrate\4.php',var_export($step1,TRUE));
             if ($step1['head']["resp_code"] == 'S0000000') {
                 //session('order_id', $params['order_id']);
                 //session('mobile', $params['mobile']);
                 //session('pay_type', $_POST['pay_type']);

                 echo json_encode(['status' => '1', 'msg' => $step1['head']["resp_desc"]]);
				 //数据入库
				 /*$data=array(
					 'id'=>$bindbank['id'],
					 'u_atpid'=>$_POST['userid'],
					 'bank_card_no'=>$bindbank['bank_card_no'],
					 'id_card_no'=>$bindbank['id_card_no'],
					 'mobile'=>$bindbank['mobile'],
					 'name'=>$bindbank['name'],
					 'status'=>1,
					 'addtime'=>time()
				 );*/
				$set['u_atpid'] = $_POST['userid'];
				$set['order_id'] = $params['order_id'];
				$set['true_money'] = $_POST['amount'];
				$set['trans_date'] = time();
				$set['pay_type'] = $_POST['pay_type'];
				
                $han1 = M('bankrecord')->add($set);
				$han  = array($han1,$set,$step1);
				file_put_contents('D:\product\91duandai\Application\Integrate\5.php',var_export($han,TRUE),FILE_APPEND);
				
             } else {
                 echo json_encode(['status' => '0', 'msg' => $step1['head']["resp_desc"]]);
             }
			 
         } else {
             echo json_encode(['status' => 0]);
         }
     }
	 
	public function bindbank(){
		//echo json_encode(['status'=>1]);return;
	file_put_contents('D:\product\blackcard\application\home\1.php',var_export($_POST,TRUE));
	
	$_POST['bankcard']='4367420110028390407';
	$_POST['name']='韩晓阳';
	$_POST['idcard']='130434199202216033';
	$_POST['phone']='15175066313';
	$_POST['yinhang']='中国建设银行';
	//return;
        // $user= M('user')->where(['u_atpid'=>$_POST['userid']])->find();
         //if($user) {
//             组装数据
           $amount=2;
		   //$amount='';
           $params=array(
               'cust_no'=>time().rand(10000, 99999),
               'order_id'=>time().rand(10000, 99999),
               'bank_card_no'=>$_POST['bankcard'],
               'id_card_no'=>$_POST['idcard'],
               'mobile'=>$_POST['phone'],
               'name'=>$_POST['yinhang'],
               //'verify_code'=>$_POST['code']
           );
           $jyttype="TD1001";
           $jinyuntong = new Jinyuntong();
             
			 $step1=$jinyuntong->bangka($params,$amount,$jyttype);
			 file_put_contents('D:\product\blackcard\application\home\2.php',var_export($step1,TRUE),FILE_APPEND);
             if($step1['head']["resp_code"]=='S0000000'){
                 session('order_id',$params['order_id']);
                 session('mobile',$params['mobile']);
                 $data=array(
                     //'u_atpid'=>$_POST['userid'],
                     'bank_card_no'=>$_POST['brand'],
                     'id_card_no'=>$_POST['cardid'],
                     'mobile'=>$_POST['iphone'],
                     'name'=>$_POST['name'],
                     'status'=>0,
                     'addtime'=>time(),
                     'cname'=>$_POST['kname']
                 );
                 M('bankcard')->add($data);
                 echo json_encode(['status'=>'1','msg'=>$step1['head']["resp_desc"]]);
                 //$bind_order_id=$step1['body']["bind_order_id"];
                 //session('bind_order_id',$bind_order_id);
             }else{
                 echo json_encode(['status'=>'0','msg'=>$step1['head']["resp_desc"]]);
             }


         //}else{
             //echo json_encode(['status'=>0]);
         //}

     }
}
